package com.tunnel.service.hendler;

import com.tunnel.service.proxy.ProxyService;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;

/**
 * 处理和客户端之间的数据交互
 */
public class HttpHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
    //读取数据
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
        if (request == null) {
            System.out.println("Received null request");
            return;
        }
        ProxyService.transferData(ctx, request);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }


}

